<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/29
 * Time: 10:48
 */
namespace common\models;

use yii\base\Model;
use yii\web\UploadedFile;

class UploadForm extends Model
{
    /**
     * @var UploadedFile
     */
    public $UploadedFile;

    public function rules()
    {
        return [
            [['UploadedFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'cer, key,pfx'],'maxSize'=>'1024*1024*3'
        ];
    }

    public function upload()
    {
        if ($this->validate()) {
            $this->UploadedFile->saveAs('uploads/' . $this->UploadedFile->baseName . '.' . $this->UploadedFile->extension);
            return true;
        } else {
            return false;
        }
    }
}